#include "../include/cam.h"

unsigned int width = 640, height = 480, s, index1;

int cam_init()
{
    cam_fd = camera_init("/dev/video0", &width, &height, &s);
    if (0 > cam_fd)
    {
        perror("cam_fd");
        return -1;
    }
    printf("w:%d\nh:%d\nsize:%d\n", width, height, s);

    if (0 > camera_start(cam_fd))
    {
        perror("cam_start");
        return -1;
    }
    return cam_fd;
}
#if 0
int pic_send(int camfd, int fd)
{
    char *buf;
    int len;
    char lenstr[20] = {0};

    camera_dqbuf(camfd, (void **)&buf, &len, &index1);

    sprintf(lenstr, "%d", len);

    write(fd, lenstr, sizeof(lenstr));
    int ret = write(fd, buf, len);
    printf("len = %d ret = %d\n", len, ret);
    if (ret < 0)
    {
        camera_exit(camfd);
    }
    camera_eqbuf(camfd, index1);
}


int run_pic_send(int *arg)
{
    int connfd = *(int *)arg; // connfd:套接字
    int camfd = cam_init();
    while (1)
    {
        pic_send(camfd, connfd);
        if (cam_fd < 0)
        {
            break;
        }
    }
    printf("111111111111111\n");
    close(connfd);
    camera_stop(camfd);
    camera_exit(camfd);
}
#endif